package com.hax.security;

import cn.hutool.crypto.SecureUtil;
import org.springframework.security.crypto.password.PasswordEncoder;

public class CustomPasswordEncoder implements PasswordEncoder {
    @Override
    public String encode(CharSequence rawPassword) {
        return SecureUtil.md5(rawPassword.toString());
    }

    /**
     * rawPassword 为前端传入的密码
     * encodedPassword 为数据库中存储的密码
     */
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        //将传入的密码做一个md5加密，然后与数据库中的密码比较
        return encodedPassword.contentEquals(SecureUtil.md5(rawPassword.toString()));
    }

}
